package com.softtown.modules.sys.controller;

import com.github.pagehelper.PageInfo;
import com.softtown.common.annotation.LogOperation;
import com.softtown.common.utils.Result;
import com.softtown.common.validator.ValidatorUtils;
import com.softtown.common.validator.group.AddGroup;
import com.softtown.modules.sys.dto.SysFeedBackDTO;
import com.softtown.modules.sys.entity.SysFeedBackEntity;
import com.softtown.modules.sys.service.SysFeedBackService;
import com.softtown.modules.sys.vo.SysFeedBackVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;


/**
 * @version v1.0
 * @ProjectName: softtown-aioffice
 * @ClassName: SysFeedBackController
 * @Description: 系统用户反馈Controller层
 * @Author: fuming
 * @Date: 2019/6/27 15:46
 */
@RestController
@RequestMapping("/sys/user/feedback")
@Api(tags = "用户反馈")
public class SysFeedBackController {

    @Resource
    private SysFeedBackService sysFeedBackService;

    /**
     * @Title: getFeedbackInfosByConditions
     * @Description: 获取反馈信息以及分页
     * @param @param [sysFeedBackDTO]
     * @return @return com.softtown.common.utils.Result
     * @author fuming
     * @throws
     * @date 2019/7/1 21:12
     */
    @PostMapping("getFeedbackList")
    @ApiOperation("获取用户反馈信息分页")
    @LogOperation("获取用户反馈信息分页")
    public Result getFeedbackInfosByConditions(@RequestBody SysFeedBackDTO sysFeedBackDTO) {
        PageInfo<SysFeedBackEntity> feedbackListByConditions = sysFeedBackService.getFeedbackListByConditions(sysFeedBackDTO);
        return new Result<PageInfo<SysFeedBackEntity>>().ok(feedbackListByConditions);
    }

    /**
     * @Title: getFeedbackDetails
     * @Description: 获取用户反馈的详情信息
     * @param @param [feedbackId]
     * @return @return com.softtown.common.utils.Result<com.softtown.modules.sys.vo.SysFeedBackVO>
     * @author fuming
     * @throws
     * @date 2019/7/1 21:21
     */
    @PostMapping("getDetailsById")
    @ApiOperation("获取用户反馈信息详情")
    @LogOperation("获取用户反馈信息详情")
    public Result<SysFeedBackVO> getFeedbackDetails(@RequestBody String feedbackId) {
        String fbDetailsId = JSONObject.fromObject(feedbackId).get("id").toString();
        SysFeedBackVO feedbackDetailsById = sysFeedBackService.getFeedbackDetailsById(Long.valueOf(fbDetailsId));
        return new Result<SysFeedBackVO>().ok(feedbackDetailsById);
    }

    /**
     * @Title: addFeedbackInfos
     * @Description: 添加反馈
     * @param @param [sysFeedBackDTO]
     * @return @return com.softtown.common.utils.Result
     * @author fuming
     * @throws
     * @date 2019/7/1 21:23
     */
    @PostMapping("addFeedback")
    @ApiOperation("添加反馈")
    @LogOperation("添加反馈")
    public Result addFeedbackInfos(@RequestBody SysFeedBackDTO sysFeedBackDTO) {
        //校验数据是否为空
        ValidatorUtils.validateEntity(sysFeedBackDTO, AddGroup.class);

        sysFeedBackService.addFeedback(sysFeedBackDTO);
        return new Result<>();
    }
}
